//处理menuList的数据类型
interface roleState {
    roleList: Array<Object>
};
//引入roleList列表接口
import { rolelist } from "../../request/api";
//引入消息提示
import { ElMessage } from "element-plus";

//数据仓库
const state = {
    roleList: [],//role页的初始数组
};
//getters 处理数据
const getters = {
    //返回处理好的menuList数据
    getRolelist(state: roleState) {
        return state.roleList;
    }
};
//唯一修改state仓库的方法 mutations
const mutations = {
    //修改roleList方法
    REQ_ROLE(state: roleState, payload: any) {
        state.roleList = payload;
    }
};
//处理异步操作的 axtions
const actions = {
    //获取role列表方法
    async changeRoleAction({ commit }: any) {
        let res: any = await rolelist();
        //判断是否获取成功
        if (res.code == 200) {
            //传输数据
            commit('REQ_ROLE', res.list);
        } else {
            ElMessage.error(res.msg);
        }
    }
};



export default {
    state, getters, mutations, actions,
    namespaced: true
}